package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import com.bnzj.core.rest.UserInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

@Getter
@Setter
@ToString(exclude = {"roleUserList", "deprtment"}, callSuper = true)
@Entity
@Table(name = "bnz_sys_user")
@Schema(description="用户")
public class SysUser extends BaseEntity implements UserInfo {
    private static final long serialVersionUID = -8725068474072021448L;

    @Schema(description = "工号")
    private String account;

    @Schema(description = "姓名")
    private String cname;

    @Schema(description = "英文名")
    private String ename;

    @Schema(description = "性别")
    private String sex;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "手机号码")
    private String phone;

    @Schema(description = "身份证号")
    private String identity;

    @Schema(description = "是否备案")
    private String isRecord;

    @Schema(description = "部门ID")
    private Long deptId;

    @Schema(description = "密码")
    @JsonIgnore
    private String password;

    @Schema(description = "员工部门全称")
    private String fullDeptName;

    @Schema(description = "员工岗位")
    private String position;

    @Schema(description = "员工岗位名称")
    @Transient
    private String positionName;

    @Schema(description = "员工状态")
    private Boolean personnel;//员工状态

    @Schema(description = "账号是否启用")
    private Boolean enabled;//账号是否启用

    @Schema(description = "账号类型(内部员工是A，与供应商员工是B)")
    private String type;//账号类型(内部员工是A，与供应商员工是B)

    @Schema(description = "关联ID(内部员工不需要关联ID，供应商员工才需要)")
    private Long linkId;//关联ID(内部员工不需要关联ID，供应商员工才需要)

    @Schema(description = "机构ID")
    private Long groupId;//机构ID
    
    @Schema(description = "k3id")
    private String idk3;//k3id

    @OneToMany(mappedBy = "userId", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    @JsonManagedReference(value = "relation-user-role")
    private List<SysRoleUser> roleUserList;

    @JsonIgnore
    @JoinColumn(name = "deptId", insertable = false, updatable = false)
    @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    private SysDepartment deprtment;

    @Override
    public String getName() {
        return getCname();
    }
    
   
    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (this == obj)
            return true;
        if (obj instanceof SysUser) {
        	SysUser vo = (SysUser) obj;
 
            // 比较每个属性的值 一致时才返回true
            if (vo.account.equals(this.account) && vo.cname.equals(this.cname))
                return true;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return account.hashCode() * cname.hashCode();
    }


}
